<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__ROOT__/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__ROOT__/layui/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main" >

        <form class="layui-form layui-form-pane" action="">

            <div class="layui-form-item">
                <label class="layui-form-label">标签类别</label>
                <div class="layui-input-inline">
                    <select name="tag_id" >
                        <option value=""></option>
                        {foreach name="list" item="vo" }
                            <option value="{$vo.name}">{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">标签名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" autocomplete="off" placeholder="请输入标签名称" lay-verify="required" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <button class="layui-btn layui-bg-blue" lay-submit lay-filter="saveTag">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary" id="cancel">取消</button>
            </div>
        </form>
    </div>
</div>
<script src="__ROOT__/static/assets/js/jquery-2.1.4.min.js" charset="utf-8"></script>
<script src="__ROOT__/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(function(){
        var $ = layui.$;
        var form = layui.form;
        var layer = layui.layer;
        // 提交事件
        form.on('submit(saveTag)', function(data){
            var url = "{:url(\'Tag/up_tag\')}";
            var data=(data.field);

            //    执行异步请求 ，$.post
            $.post(url,data,function(result){
                if(result.status ==0){
                    layer.open({
                        content:result.message,
                        icon:2,
                        title : '错误提示'
                    });

                }
                if(result.status ==1){
                    layer.open({
                        content : result.message,
                        icon : 1,
                        yes : function(){
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name)
                                parent.layer.close(index);
                            }, 500);
                        }
                    });

                }

            },'JSON');
            return false;
        });
        $("#cancel").on("click", function(){
            window.parent.location.reload(); //刷新父页面
            var index = parent.layer.getFrameIndex(window.name)
            parent.layer.close(index);
        });
    });
</script>

</body>
</html>